package com.jiedeng.dao;

import com.jiedeng.model.ProjectPerson;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author 覃远龙
 * @ClassName: IProjectPersonRepository
 * @Description:
 * @date 2017/8/4 10:21
 */
public interface IProjectPersonRepository extends JpaRepository<ProjectPerson, Long> {

    List<ProjectPerson> findByPersonId(long personId);

    List<ProjectPerson> findByPersonIdAndProjectIdAndPostId(long personId, long ProjectId, long postId);

    List<ProjectPerson> findByProjectIdAndPostId(long ProjectId, long postId);

    List<ProjectPerson> findByProjectId(long ProjectId);

    @Query(nativeQuery = true, value =  " select tpp.id , tpp.Project_ID ,tpp.Person_ID ,tpp.Post_ID  from t_project_person tpp left JOIN "+
            " ( select DISTINCT tcc.Person_ID , tcc.Corp_WeightLevel , tcc.name from t_check tc LEFT JOIN t_checkcount tcc on tc.ID = tcc.Check_ID "+
            " where tc.Task_ID = ?1 ) a on a.Person_ID = tpp.Person_ID "+
            " where tpp.Project_ID = ?2 and tpp.Post_ID = ?3 "+
            " ORDER BY a.Corp_WeightLevel is null, FIND_IN_SET(a.Corp_WeightLevel,'主要责任单位,次要责任单位,相关责任单位'), a.Person_ID DESC ")
    List<ProjectPerson> findProjectPerson(String taskId,long projectId, long postId);



}
